package cn.com.servletconfig;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "sConfig", value = "/sConfig",initParams = {@WebInitParam(name="encoding",value = "UTF-8")})
public class sConfig extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out=response.getWriter();
        //获得ServletConfig对象
        ServletConfig config=this.getServletConfig();
        //获得参数名为encoding对应的参数值
        String param=config.getInitParameter("encoding");
        out.println("encoding="+param);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
